<template>
    <div class='fxn-body'>
        <Searchs v-model:searchData="searchData" v-model:SearchForm="SearchForm" @handleSearch="handleSearch"></Searchs>
        <!-- Search End -->
        <div class="fxn-section fixed fxn-margin-t-20">
            <el-table v-loading="loading" :data="listData">
                <el-table-column label="案件名称" prop="title">
                    <template #default="scope">
                        <el-link type="primary" :underline="false" @click="handlePath(scope.row)">{{scope.row.title}}</el-link>
                    </template>
                </el-table-column>
                <el-table-column label="保全期限开始时间" prop="security_start_time">
                    <template #default="scope">
                        {{$filter.dateTime(scope.row.security_start_time)}}
                    </template>
                </el-table-column>
                <el-table-column label="保全期限结束时间" prop="security_end_time">
                    <template #default="scope">
                        {{$filter.dateTime(scope.row.security_end_time)}}
                    </template>
                </el-table-column>
                <el-table-column label="申请保全金额" prop="security_amount" />
                <el-table-column label="实际保全金额" prop="apply_security_amount" />
                <el-table-column label="保全标的物" prop="security_thing" />
                <el-table-column label="创建时间" prop="create_time">
                    <template #default="scope">
                        {{$filter.dateTime(scope.row.create_time,1)}}
                    </template>
                </el-table-column>
                <el-table-column label="创建人" prop="create_with" />
                <el-table-column label="操作" prop="create_with" width="120">
                    <template #default="scope">
                        <el-link type="primary" :underline="false" @click="handleDetail(scope.row)">查看</el-link>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- Section End -->

        <div class="fxn-page fixed">
            <el-pagination v-model:current-page="page" v-model:page-size="perPage" :page-sizes="[10, 50, 100, 200, 500]" layout="total, sizes, prev, pager, next" :total="count" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </div>
        <!-- Page End -->

        <!-- 查看 -->
        <el-dialog title="查看" v-model="detailDialog" width="800">
            <el-descriptions :column="2" border>
                <el-descriptions-item label="案件名称">{{detailData.title}}</el-descriptions-item>
                <el-descriptions-item label="保全期限开始时间">{{$filter.dateTime(detailData.security_start_time)}}</el-descriptions-item>
                <el-descriptions-item label="保全期限结束时间">{{$filter.dateTime(detailData.security_end_time)}}</el-descriptions-item>
                <el-descriptions-item label="申请保全金额">{{detailData.security_amount}}</el-descriptions-item>
                <el-descriptions-item label="实际保全金额">{{detailData.apply_security_amount}}</el-descriptions-item>
                <el-descriptions-item label="保全标的物">{{detailData.security_thing}}</el-descriptions-item>
                <el-descriptions-item label="创建人">{{detailData.create_with}}</el-descriptions-item>
                <el-descriptions-item label="创建时间">{{$filter.dateTime(detailData.create_time,1)}}</el-descriptions-item>
            </el-descriptions>
            <el-descriptions :column="1" border>
                <el-descriptions-item label="备注">{{detailData.remark}}</el-descriptions-item>
            </el-descriptions>
        </el-dialog>
        <!-- 查看 End -->
    </div>
</template>

<script>
    import Searchs from '../Common/Search.vue'
    import { defineComponent, reactive, getCurrentInstance, onMounted, toRefs, computed } from 'vue'
    import { useRouter } from 'vue-router'
    import { useStore } from 'vuex'
    export default defineComponent({
        components: {Searchs},
        setup() {
            const { proxy } = getCurrentInstance();
            const router = useRouter();
            const store = useStore();

            //初始化数据
            const state = reactive({
                count: 0,
                page: 0,
                perPage: 10,
                loading: false,
                listData: [],

                //搜索
                SearchForm: {
                    title: '',
                    security_start_time: '',
                    security_end_time: '',
                },
                searchData: [
                    {label: '案件名称', prop: 'title', type: 'input'},
                    {label: '开始时间', prop: 'security_start_time', type: 'daterange'},                    
                    {label: '结束时间', prop: 'security_end_time', type: 'daterange'},                    
                ],

                //查看
                detailDialog: false,
                detailData: {},
            })

            //列表
            const getList = (page,perPage) => {
                state.loading = true;
                proxy.$http.get('/oa/Lawcase/preservations',{
                    page: page ? page : 1,
                    perPage: perPage ? perPage : 10,
                    title: state.SearchForm.title,
                    security_start_time: String(state.SearchForm.security_start_time),
                    security_end_time: String(state.SearchForm.security_end_time),
                })
                .then(res=> {
                    state.loading = false;
                    const { code, msg ,data } = res;
                    if(code != 1){
                        return proxy.$msg.error(msg);
                    }else{
                        state.count = data.count;
                        state.page = data.page;
                        state.perPage = data.perPage;
                        state.listData = data.list;
                    }
                })
            }

            //查看
            const handleDetail = (row) => {
                proxy.$http.get('/oa/Lawcase/preservationForm',{id: row.id})
                .then(res=> {
                    const { code, msg ,data } = res;
                    if(code != 1){
                        return proxy.$msg.error(msg);
                    }else{
                        state.detailData = data;
                        state.detailData.title = row.title;
                        state.detailDialog = true;
                    }
                })
            }

            //跳转详情
            const handlePath = (row) => {
                router.push({path: '/CaseDetail', query: {id: row.lawcase_id, type: row.case_type, pathUrl: '/CasePreservation'}})
            }

            //搜索
            const handleSearch = (e) => {
                state.SearchForm = e;
                getList(1,10);
            }

            //分页
            const handleSizeChange = (val) => {
                state.perPage = val;
                getList(state.page,state.perPage);
            }

            //页码
            const handleCurrentChange = (val) => {
                state.page = val;
                getList(state.page,state.perPage);
            }

            //获取权限
            const authMenu = (value) => {
                let currentRouter = router.currentRoute.value.path;
                let menuArr = (proxy.$public.authMenu(currentRouter).split(','));
                for (let index = 0; index < menuArr.length; index++) {
                    if(value == menuArr[index]){
                        return true
                    }
                }
            }
            
            //Dom加载
            onMounted(()=>{
                authMenu();
                getList();
            })
            
            return {
                ...toRefs(state),
                
                //请求方法
                getList,
                handleDetail,
                
                //组件方法
                authMenu,
                handlePath,
                handleSearch,
                handleSizeChange,
                handleCurrentChange,
            }

        },
    })
</script>

<style scoped>
    
</style>